﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.ComponentModel;

namespace Agile.Manager.Util
{
    public abstract class ObservableObject: INotifyPropertyChanged
    {
        protected void RaisePropertyChanged(string propertyName)
        {
            
            this.VerifyPropertyName(propertyName);

            PropertyChangedEventHandler handler = this.PropertyChanged;
            if (handler != null)
            {
                var e = new PropertyChangedEventArgs(propertyName);
                handler(this, e);
            }
        }

        
        public void VerifyPropertyName(string propertyName)
        {
            if (String.IsNullOrEmpty(propertyName))
                return;

            if (TypeDescriptor.GetProperties(this)[propertyName] == null)
            {
                 throw new ArgumentException("The property doesn't exist",propertyName);
            }
        }

        public event PropertyChangedEventHandler PropertyChanged;
    }
}
